const http = require("http");
const fs=require("fs");
const notifier=require("node-notifier");
const path = require("path");
const type=require("./contentType.json");
const router=require("./router");


const server=http.createServer(function(req,res){

    //req.url获取localhost:3000后的链接
        let urlPath=req.url;

        let reg=/^\/static/;

//将静态文件和非静态文件通过模块文件来引入

    try{
        if(reg.test(urlPath)){
            router.readStatic(req,res);
        }else{
            router.urlPathParse(req,res);
        }
    }catch(error){
        console.log(error);
        res.writeHead(404); //?
        res.end("请求失败");
    }
});

    server.listen(3000,function(){
        console.log("服务器启动成功，监听localhost:3030");
        notifier.notify('服务器启动成功');
    });

    server.on("error",function(error){
        console.log("服务器启动失败"+error.message);
        notifier.notify('服务器启动失败'+error.message);
    })
